package com.team.ssm_item_lj.controller;

import com.team.ssm_item_lj.entity.JavaeeTeam;
import com.team.ssm_item_lj.service.JavaeeTeamService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;

import java.util.Date;
import java.util.List;

/**
 * 开发团队表(JavaeeTeam)表控制层
 *
 * @author zhuxhenxin
 * @since 2024-12-05 10:44:29
 */
@RestController
@RequestMapping("javaeeTeam")
public class JavaeeTeamController {
    /**
     * 服务对象
     */
    @Resource
    private JavaeeTeamService javaeeTeamService;



    /**
     * 对象条件查询
     */
    @GetMapping("queryByJavaeeTeam")
    public List<JavaeeTeam> queryByJavaeeTeam(JavaeeTeam searchInfo) {
        System.out.println("对象条件查询：" + searchInfo);
        return javaeeTeamService.queryByJavaeeTeam(searchInfo);
    }


    /**
     * 分页查询
     *
     * @param javaeeTeam 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping("queryByPage")
    public ResponseEntity<Page<JavaeeTeam>> queryByPage(JavaeeTeam javaeeTeam, PageRequest pageRequest) {
        System.out.println("分页查询：" + javaeeTeam);
        System.out.println("分页对象：" + pageRequest);

        return ResponseEntity.ok(this.javaeeTeamService.queryByPage(javaeeTeam, pageRequest));
    }

    @RequestMapping("/queryAll")
    public List<JavaeeTeam> queryAll() {

        return this.javaeeTeamService.queryAll();
    }

    /**
     * 通过主键查询单条数据  javaeeTeam/1001
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<JavaeeTeam> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.javaeeTeamService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param  newInfo
     * @return 新增结果
     */
    @PostMapping("save")
    public ResponseEntity<JavaeeTeam> add(@RequestBody JavaeeTeam newInfo) {

        newInfo.setCreateTime(new Date());
        newInfo.setUpdateTime(new Date());
        newInfo.setCreateUser("tzhu");
        newInfo.setUpdateUser("tzhu");
        newInfo.setDeleted(1);
        newInfo.setVersion(1000);
        System.out.println("新增数据：" + newInfo);
        return ResponseEntity.ok(this.javaeeTeamService.insert(newInfo));
    }

    /** @return 编辑结果
     */
    @PutMapping("update")
    public ResponseEntity<JavaeeTeam> edit(@RequestBody  JavaeeTeam javaeeTeam) {
        System.out.println("修改javaeeTeam = " + javaeeTeam);
        return ResponseEntity.ok(this.javaeeTeamService.update(javaeeTeam));
    }

    /**
     * 删除数据     javaeeTeam/1001
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable("id") Long id) {
        System.out.println("删除数据：" + id);
        return ResponseEntity.ok(this.javaeeTeamService.deleteById(id));
    }

}

